#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

#define N 5



void Runchild()
{
    int cnt = 5;
    while(cnt--)
    //while(1)//如果子进程不死呢
    {
        printf("i am child,pid:%d ,ppid:%d \n",getpid(),getppid());
        sleep(1);
    }
}


int main()
{
    int i = 0;
    for(;i<N;++i)
    {
        pid_t id = fork();
        if(id == 0)
        {
            Runchild();
            exit(i);
        }
        printf("creat child process success:%d \n",id);
    }
    
    
    for(i = 0;i < N;i++)
    {
     //   pid_t id = wait(NULL);
        
        int status = 0;

        pid_t id = waitpid(-1,&status,0);

        if(id > 0)
        {
            printf("wait id: %d , exid code: %d succes\n",id,WEXITSTATUS(status));
        }
    }
    sleep(5);

    return 0;
}
